home *** CD-ROM | disk | FTP | other *** search
/ BlastDOS / pcANYWHERE 2.0.zip / Disk 2.IMA / COMPUSRV.SC$ / COMPUSRV.SCR
Text File  |  1995-08-11  |  8KB  |  178 lines

  1. description "Sample Script To Log Onto Compuserve"
  2. ;
  3. ; This is a sample script that shows how to log onto Compuserve.
  4. ; Your name and password are stored (encrypted) in a file named
  5. ; COMPUSRV.DAT. If the file does not exist, you are prompted for your
  6. ; UserID and password when the "User Id:" prompt is received.
  7. ; The script displays all initial screens and automatically responds with
  8. ; your name and password when appropriate.
  9. ; The script ends after the main menu is displayed.
  10. ; You regain keyboard control when the main is menu is displayed, if you
  11. ; press ESC, or if 10 seconds goes by without a recognizable prompt.
  12.  
  13. ;==========================================================================
  14. ;                          VARIABLE DECLARATION
  15. ;==========================================================================
  16.       string _s1[120]                                               ;string for various uses
  17.       string _s2[120]                   ;string for various uses
  18.       string _name[30]                  ;name stored here
  19.       string _password[16]              ;password stored here
  20.       string _datFile[80]               ;name of DAT file stored here
  21.       string _key[1]                    ;for inputting a key
  22.       integer _i1                       ;integer for various uses
  23. ;==========================================================================
  24. ;                                                                               MAIN ROUTINE
  25. ;==========================================================================
  26.       clear screen                      ;clear the screen
  27.  
  28.       _datFile = "COMPUSRV.DAT"         ;name of encrypted data file
  29.  
  30.       find first _datFile               ;check if DAT file exists
  31.       if ($result == 0) goto @l5        ;not yet - will create later
  32.  
  33.       open 1 _datFile                   ;open the file
  34.       read line 1 _name 30 0            ;read the login name
  35. ;For maximum security, should ask user for the encryption key word
  36.       decrypt _name "MICKEY"            ;decrypt
  37.       trim _name                        ;remove trailing/leading spaces
  38.       read line 1 _password 16 0        ;read the password
  39.       decrypt _password "MICKEY"        ;decrypt
  40.       trim _password                    ;remove trailing/leading spaces
  41.       close 1                                                                        ;close the file
  42.  
  43. @l5:
  44.       set cancel on                     ;enable ESC to cancel the script
  45.       on cancel goto @cancel
  46.  
  47.       on timeout goto @timeout          ;setup overall timeout
  48.       set timeout 20                    ;to 20 seconds
  49.  
  50.       set disconnect on                 ;set disconnection trap
  51.       on disconnect goto @disconnect
  52.  
  53.       Send string "^C"                  ;anounce our presence
  54.  
  55. @L10:                                                                                    ;main loop starts here:
  56.       Gosub @getPrompt                  ;wait for a prompt line
  57.       if ($result < 0) goto @timeout    ;if we timed out, end the script
  58.  
  59. @L40:
  60.       index _s1 "User Id:"              ;if prompting for "userid", send ID
  61.       if ($RESULT == 0) goto @L50
  62.       strcmp _name ""                   ;if don't have a name,
  63.       if ($result == 0) then gosub @getData ;input from user
  64.       Send string _name                 ;send the name
  65.       Send string "^M"                  ;and a CR
  66.       Goto @L10
  67.  
  68. @L50:                                                                                    ;if prompting for "password", send it
  69.       Set ignorecase off                ;Do this for exact match of "Password"
  70.       Index _s1 "Password:"             ;check if "Password"
  71.       If ($result == 0) goto @L55       ;branch if not
  72.       Send string _password             ;else send it
  73.       Send string "^M"                  ;and a CR
  74.  
  75.       Goto @end
  76.  
  77. @L55:
  78.       Set ignorecase on
  79.       Goto @L10
  80.  
  81. @timeout:                                                                                ;a timeout occurred, end the script
  82.       Type string "^M^J(timeout)^M^J"
  83.       Goto @end
  84.  
  85. @cancel:                                                                                 ;user cancelled, so end the script
  86.       set cancel off
  87. @cancel1:
  88.       type string "^M^JOperator Cancel^M^J"
  89.       type string "Hang up (Y/N) ?: "   ;ask if should hang up
  90.       _s1 = ""                          ;clear input variable
  91.       input _s1 1                       ;input name
  92.       upper _s1
  93.       strcmp _s1 "Y"
  94.       if ($result == 0) goto @cancel2   ;if Yes, branch to @cancel2 to hangup
  95.       strcmp _s1 "N"
  96.       if ($result != 0) goto @cancel1   ;branch if neither Y or N entered
  97.       goto @end                         ;if No, don't hang up but stay
  98.                                                     ;in terminal mode.
  99. @cancel2:
  100.       type string "^M^JHANGING UP..."
  101.       Hang
  102.       End
  103. @disconnect:                                                                     ;disconnection, so end the script
  104.       Type string "^M^J(disconnected)^M^J"
  105.       Goto @end
  106.  
  107. @end:
  108.       beep                                                                           ;so you know the script has ended
  109.       type string "^M^J[YOU ARE NOW IN TERMINAL MODE]^M^J"
  110.       end terminal
  111.  
  112.  
  113. ;==========================================================================
  114. ;                                                                               SUBROUTINES
  115. ;==========================================================================
  116.  
  117. ; "@getPrompt" - wait for a prompt line and store it into _s1.
  118. ;                All lines received are displayed.
  119. ;                Returns: >=0, length of string
  120. ;                         < 0, timeout occurred
  121. @getPrompt:
  122.       on timeout goto @g2
  123.       wait receive 10                   ;wait for something to be received
  124.       _s1 = ""
  125.       on timeout goto @g1
  126.       set timeout 2                     ;wait 2 seconds for a line
  127.       receive line _s1                  ;(will timeout if a prompt received)
  128.       type line _s1                     ;full line - display on the screen
  129.       goto @getPrompt                   ;and wait for another line
  130.  
  131. @g1:                                                                                             ;did not get LF, so must be a prompt
  132.       Type string _s1                   ;display on the screen
  133.       strlen _s1 _i1
  134.       goto @g3                                                                       ;and return
  135.  
  136. @g2:                                                                                             ;timeout without getting anything
  137.       _i1 = -1                                                                       ;means something is wrong
  138. @g3:
  139.       on timeout goto @timeout          ;restore normal timeout
  140.       set timeout 20
  141.       return _i1                        ;return line length or -1 if timeout
  142.  
  143.  
  144. ; @getData: input login name and password from the user and write to disk.
  145. @getData:
  146.       set cancel off
  147. @gd2:
  148.       type string "^M^J^JEnter CompuServe Id: "
  149.       _s1 = ""                          ;clear input variable
  150.       input _s1 30                      ;input name
  151.       _name = _s1
  152.       encrypt _s1 "MICKEY"              ;encrypt it
  153.       type string "^M^J^JEnter Password: "
  154.       _s2 = ""
  155.       input _s2 16                      ;input password
  156.       _password = _s2
  157.       encrypt _s2 "MICKEY"              ;encrypt it
  158.  
  159.       type string "^M^J^JOK (Y/N) ?:"   ;ask if ok
  160. @gd0:
  161.       input key _key                    ;input Y or N
  162.       upper _key                        ;upper case the response
  163.       strcmp _key "Y"
  164.       if ($result == 0) goto @gd1       ;branch if yes to save in file
  165.       strcmp _key "N"
  166.       if ($result != 0) goto @gd0       ;branch if did not press Y or N
  167.       goto @gd2                         ;branch if no to get again
  168. @gd1:                                                                                    ;save data in file
  169.       create 1 _datfile                 ;create the file
  170.       write string 1 _s1                ;save name
  171.       write string 1 "^@"               ;follow with a null terminator
  172.       write string 1 _s2                ;save password
  173.       write string 1 "^@"               ;follow with a null terminator
  174.       close 1                                                                        ;close file
  175.       set cancel on
  176.       re